﻿#include "OpenGLBuffer.h"

using namespace Kriko;

OpenGLBuffer::OpenGLBuffer(GLfloat* data, GLsizei count, GLsizei componentCount) : componentCount(componentCount) {
    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ARRAY_BUFFER, count * sizeof(GLfloat), data, GL_STATIC_DRAW);
    Unbind();
}
OpenGLBuffer::OpenGLBuffer(const std::vector<glm::vec2>& data) : componentCount(2) {
    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(glm::vec2), &data[0], GL_STATIC_DRAW);
    Unbind();
}
OpenGLBuffer::OpenGLBuffer(const std::vector<glm::vec3>& data) : componentCount(3) {
    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(glm::vec3), &data[0], GL_STATIC_DRAW);
    Unbind();
}
OpenGLBuffer::OpenGLBuffer(const std::vector<glm::vec4>& data) : componentCount(4) {
    glGenBuffers(1, &bufferID);
    Bind();
    glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(glm::vec4), &data[0], GL_STATIC_DRAW);
    Unbind();
}
OpenGLBuffer::~OpenGLBuffer() {
    glDeleteBuffers(1, &bufferID);
}

void OpenGLBuffer::Bind() {
    glBindBuffer(GL_ARRAY_BUFFER, bufferID);
}

void OpenGLBuffer::Unbind() {
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

GLsizei OpenGLBuffer::GetComponentCount() const {
    return componentCount;
}